<?php

namespace app\index\model;

use think\Model;

class CityModel extends Model
{
    protected $table = 'newzs_city';


    /**
     * 根据pid获取以下地区
     * @param $pid
     * @return array|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function get_list_by_pid($pid){
        return self::where(['pid'=>$pid])->select();
    }

    /**
     * 根据id获取地区名称
     * @param $id
     * @return mixed
     */
    public static function get_name_by_id($id){
        return self::where(['id'=>$id])->value('name');
    }

    /**
     * 根据省市区id获取完整地区名称 如四川成都高新区
     * @param $proid  int 省id
     * @param $cityid int 市id
     * @param $countyid int 区id
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function get_areaid_by_name($proid=0, $cityid=0, $countyid=0){
        $name = '';
        $areaid = $proid.','.$cityid.','.$countyid;
        $data = self::where('id', 'in', $areaid)->select();
        foreach ($data as $k=>$v){
            $name .= $v['name'];
        }
        return $name;
    }

}

